package com.gz.spring.aop.homework.Aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyCalAspect {

    @Pointcut(value = "execution(public int MyCal.cal1(int)) || execution(public int MyCal.cal2(int))")
    public void myPointCut() {}

    @Before(value = "myPointCut()")
    public  void showBeginLog(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        System.out.println("注解配置-切面类的showBeginLog-开始执行计算  "+System.currentTimeMillis());//从AOP看，这里是一个横切关注点-前置通知
    }

    @AfterReturning(value = "myPointCut()",returning = "res")
    public  void showSuccessEndLog(JoinPoint joinPoint,Object res) {
        Signature signature = joinPoint.getSignature();
        System.out.println("注解配置-切面类的showSuccessEndLog-正常结束执行计算  "+System.currentTimeMillis()
        +"\n"+"结果= "+res);//从AOP看，也是一个横切关注点-返回通知
    }

    @AfterThrowing(value = "myPointCut()",throwing = "e")
    public  void showExceptionLog(JoinPoint joinPoint,Exception e) {
        Signature signature = joinPoint.getSignature();
        System.out.println("注解配置-切面类的showExceptionLog-执行异常  "+System.currentTimeMillis());//从AOP看，也是一个横切关注点-异常通知
    }

    @After(value = "myPointCut()")
    public  void showFinallyEndLog(JoinPoint joinPoint){
        Signature signature = joinPoint.getSignature();
        System.out.println("注解配置-切面类的showFinallyEndLog-最终执行计算  "+System.currentTimeMillis());//从AOP看，也是一个横切关注点-最终通知
    }
}
